package com.wisemoresystem.seal.action.seal.error;

import java.util.List;
import java.util.Map;

import org.ne.framework.data.util.ChkTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_seal;
import com.wisemoresystem.seal.model.t_seal_handle;
import com.wisemoresystem.seal.model.t_seal_new;
import com.wisemoresystem.seal.model.t_seal_type_config;
import com.wisemoresystem.seal.service.SealErrorService;
import com.wisemoresystem.seal.service.SealSetService;
import com.wisemoresystem.seal.web.WebTools;

/**
 * 印章 不符处理
 * 
 * @author hxj
 */
@Controller("ixSealError")
@Scope("prototype")
@RequestMapping("/ix/seal/error")
public class SealErrorAction extends ProjBaseAction {

	@Autowired
	private SealErrorService service;
	@Autowired
	private SealSetService setService;

	/**
	 * 印章不符列表
	 * 
	 * @param srh_name
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list(String srh_name) {

		List<Map<String, Object>> list = service.selectSealErrorList(
				WebTools.getCurrentBankId(), srh_name, page);

		ModelAndView mv = new ModelAndView("/jsp/seal/error/list");
		mv.addObject("list", list);
		return mv;
	}

	/**
	 * 不符印章详细信息
	 * 
	 * @param seal_id
	 *            印章id
	 * @return
	 */

	@RequestMapping("/error_form")
	public ModelAndView error_form(String seal_id) {

		t_seal seal = service.findObjById(seal_id, t_seal.class);

		ModelAndView mv = new ModelAndView("/jsp/seal/error/error_form");
		mv.addObject("seal", seal);
		if (ChkTools.isNotNull(seal.getSeal_new_id())) {
			t_seal_new seal_new = service.findObjById(seal.getSeal_new_id(),
					t_seal_new.class);
			if (ChkTools.isNotNull(seal_new.getSeal_type_config_id())) {
				t_seal_type_config config = service.findObjById(
						seal_new.getSeal_type_config_id(),
						t_seal_type_config.class);
				mv.addObject("config", config);
			}
			mv.addObject("seal_new", seal_new);
		}
		// 判断盖章是否在销毁权限之上
		if (setService.checkIsTop(seal_id))
			mv.addObject("lev", 0);
		return mv;
	}

	// 销毁上缴
	/**
	 * 销毁上缴
	 * 
	 * @param seal_id
	 *            印章id
	 * @param handle
	 *            处理信息
	 * @return
	 */
	@RequestMapping("/error")
	public ModelAndView error(String seal_id, t_seal_handle handle) {

		if (service.error(seal_id, handle)) {
			super.setTipMsg("操作成功!", Tip.Type.success);
		} else {
			super.setTipMsg("操作失败!", Tip.Type.error);
		}
		logT.logH("印章不符处理", t_seal.class, seal_id);
		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}

}
